```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>单例模式线程安全实现指南</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        h1, h2, h3, h4 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 600;
        }
        .hero-bg {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .code-block {
            background: #2d3748;
            border-radius: 8px;
            position: relative;
        }
        .code-header {
            background: rgba(0,0,0,0.2);
            padding: 8px 16px;
            border-top-left-radius: 8px;
            border-top-right-radius: 8px;
            display: flex;
            align-items: center;
        }
        .code-dots {
            display: flex;
            gap: 6px;
        }
        .code-dot {
            width: 12px;
            height: 12px;
            border-radius: 50%;
        }
        .code-dot:nth-child(1) {
            background: #ff5f56;
        }
        .code-dot:nth-child(2) {
            background: #ffbd2e;
        }
        .code-dot:nth-child(3) {
            background: #27c93f;
        }
        .code-content {
            padding: 16px;
            overflow-x: auto;
        }
        .pros-cons {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 16px;
        }
        .card {
            transition: all 0.3s ease;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
        }
        .card:hover {
            transform: translateY(-4px);
            box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
        }
        .highlight {
            position: relative;
        }
        .highlight:after {
            content: '';
            position: absolute;
            bottom: 2px;
            left: 0;
            width: 100%;
            height: 10px;
            background: rgba(118, 75, 162, 0.2);
            z-index: -1;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <div class="hero-bg text-white py-20 px-6">
        <div class="max-w-5xl mx-auto">
            <h1 class="text-4xl md:text-5xl font-bold mb-6">单例模式<span class="highlight">线程安全</span>实现指南</h1>
            <p class="text-xl md:text-2xl opacity-90 mb-8">探索多线程环境下确保单例模式安全的多种实现方式及其优劣分析</p>
            <div class="flex items-center space-x-4">
                <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm font-medium">
                    <i class="fas fa-lock mr-2"></i>线程安全
                </span>
                <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm font-medium">
                    <i class="fas fa-bolt mr-2"></i>性能优化
                </span>
                <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm font-medium">
                    <i class="fas fa-shield-alt mr-2"></i>设计模式
                </span>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="max-w-5xl mx-auto px-6 py-12">
        <!-- Introduction -->
        <div class="mb-16">
            <p class="text-lg text-gray-700 leading-relaxed mb-6">
                在多线程环境中，确保单例模式的线程安全至关重要。不当的实现可能导致多个实例被创建，从而破坏单例模式的核心原则。本文将详细介绍四种常见的线程安全单例实现方式，分析它们的优缺点，并帮助您选择最适合您场景的方案。
            </p>
            <div class="bg-blue-50 border-l-4 border-blue-500 p-4">
                <div class="flex">
                    <div class="flex-shrink-0">
                        <i class="fas fa-info-circle text-blue-500 text-xl"></i>
                    </div>
                    <div class="ml-3">
                        <h3 class="text-sm font-medium text-blue-800">关键提醒</h3>
                        <div class="mt-2 text-sm text-blue-700">
                            <p>单例模式的线程安全问题主要出现在延迟初始化的场景中。如果你能接受类加载时就创建实例，饿汉式是最简单安全的选择。</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Visualization -->
        <div class="mb-16 bg-white rounded-xl p-6 shadow-md">
            <h2 class="text-2xl font-bold mb-6 text-gray-800">单例模式实现方式对比</h2>
            <div class="mermaid">
                graph TD
                    A[单例模式] --> B[饿汉式]
                    A --> C[懒汉式]
                    C --> C1[同步方法]
                    C --> C2[双重检查锁]
                    A --> D[静态内部类]
                    A --> E[枚举方式]
                    classDef green fill:#e6ffed,stroke:#38a169;
                    classDef yellow fill:#fefff1,stroke:#d69e2e;
                    classDef red fill:#fff5f5,stroke:#e53e3e;
                    class B green
                    class D green
                    class E green
                    class C1 yellow
                    class C2 yellow
            </div>
            <div class="mt-6 grid grid-cols-1 md:grid-cols-4 gap-4">
                <div class="bg-green-50 p-4 rounded-lg border border-green-200">
                    <h3 class="font-medium text-green-800 mb-2"><i class="fas fa-check-circle mr-2 text-green-500"></i>推荐方式</h3>
                    <p class="text-sm text-green-700">饿汉式、静态内部类、枚举方式</p>
                </div>
                <div class="bg-yellow-50 p-4 rounded-lg border border-yellow-200">
                    <h3 class="font-medium text-yellow-800 mb-2"><i class="fas fa-exclamation-circle mr-2 text-yellow-500"></i>谨慎使用</h3>
                    <p class="text-sm text-yellow-700">同步方法、双重检查锁</p>
                </div>
                <div class="bg-blue-50 p-4 rounded-lg border border-blue-200 md:col-span-2">
                    <h3 class="font-medium text-blue-800 mb-2"><i class="fas fa-lightbulb mr-2 text-blue-500"></i>选择建议</h3>
                    <p class="text-sm text-blue-700">优先考虑静态内部类或枚举方式，它们结合了线程安全和延迟初始化的优点</p>
                </div>
            </div>
        </div>

        <!-- 1. Eager Initialization -->
        <div class="mb-16">
            <div class="flex items-center mb-6">
                <span class="bg-purple-100 text-purple-800 font-bold rounded-full w-8 h-8 flex items-center justify-center mr-4">1</span>
                <h2 class="text-2xl font-bold text-gray-800">饿汉式（Eager Initialization）</h2>
            </div>
            <p class="text-gray-700 mb-6">这种方法在类加载时立即创建实例。由于 JVM 保证了类加载的线程安全性，这种方式天生是线程安全的。</p>
            
            <div class="mb-8">
                <div class="code-block">
                    <div class="code-header">
                        <div class="code-dots mr-4">
                            <div class="code-dot"></div>
                            <div class="code-dot"></div>
                            <div class="code-dot"></div>
                        </div>
                        <span class="text-gray-300 text-sm">Singleton.java</span>
                    </div>
                    <div class="code-content">
                        <pre class="text-gray-200"><code>public class Singleton {
    // 1. 创建一个静态的唯一实例
    private static final Singleton INSTANCE = new Singleton();

    // 2. 私有化构造函数，防止外部实例化
    private Singleton() {}

    // 3. 提供一个公共的静态方法来获取唯一实例
    public static Singleton getInstance() {
        return INSTANCE;
    }
}</code></pre>
                    </div>
                </div>
            </div>
            
            <div class="pros-cons mb-6">
                <div class="bg-green-50 p-4 rounded-lg">
                    <h3 class="font-medium text-green-800 mb-2 flex items-center"><i class="fas fa-thumbs-up mr-2"></i>优点</h3>
                    <ul class="list-disc pl-5 text-green-700 space-y-1">
                        <li>实现简单直接</li>
                        <li>线程安全性由JVM保证</li>
                        <li>无需考虑同步问题</li>
                    </ul>
                </div>
                <div class="bg-red-50 p-4 rounded-lg">
                    <h3 class="font-medium text-red-800 mb-2 flex items-center"><i class="fas fa-thumbs-down mr-2"></i>缺点</h3>
                    <ul class="list-disc pl-5 text-red-700 space-y-1">
                        <li>无论是否使用都会创建实例</li>
                        <li>可能导致不必要的资源消耗</li>
                    </ul>
                </div>
            </div>
            
            <div class="bg-gray-100 p-4 rounded-lg">
                <h3 class="font-medium text-gray-800 mb-2 flex items-center"><i class="fas fa-question-circle mr-2 text-gray-600"></i>适用场景</h3>
                <p class="text-gray-700">适用于实例创建开销不大，且程序运行过程中肯定会使用的单例对象。</p>
            </div>
        </div>

        <!-- 2. Lazy Initialization -->
        <div class="mb-16">
            <div class="flex items-center mb-6">
                <span class="bg-purple-100 text-purple-800 font-bold rounded-full w-8 h-8 flex items-center justify-center mr-4">2</span>
                <h2 class="text-2xl font-bold text-gray-800">懒汉式（Lazy Initialization）</h2>
            </div>
            <p class="text-gray-700 mb-6">懒汉式会在第一次调用 <code class="bg-gray-100 px-1 py-0.5 rounded">getInstance()</code> 方法时才创建实例。为了保证线程安全，需要使用同步机制。</p>
            
            <h3 class="text-xl font-semibold text-gray-800 mb-4 pl-2 border-l-4 border-purple-500 px-3">2.1 同步方法</h3>
            <div class="mb-6">
                <div class="code-block">
                    <div class="code-header">
                        <div class="code-dots mr-4">
                            <div class="code-dot"></div>
                            <div class="code-dot"></div>
                            <div class="code-dot"></div>
                        </div>
                        <span class="text-gray-300 text-sm">Singleton.java</span>
                    </div>
                    <div class="code-content">
                        <pre class="text-gray-200"><code>public class Singleton {
    private static Singleton instance;

    private Singleton() {}

    public static synchronized Singleton getInstance() {
        if (instance == null) {
            instance = new Singleton();
        }
        return instance;
    }
}</code></pre>
                    </div>
                </div>
            </div>
            
            <div class="pros-cons mb-8">
                <div class="bg-green-50 p-4 rounded-lg">
                    <h3 class="font-medium text-green-800 mb-2 flex items-center"><i class="fas fa-thumbs-up mr-2"></i>优点</h3>
                    <ul class="list-disc pl-5 text-green-700 space-y-1">
                        <li>实现了延迟初始化</li>
                        <li>线程安全</li>
                    </ul>
                </div>
                <div class="bg-red-50 p-4 rounded-lg">
                    <h3 class="font-medium text-red-800 mb-2 flex items-center"><i class="fas fa-thumbs-down mr-2"></i>缺点</h3>
                    <ul class="list-disc pl-5 text-red-700 space-y-1">
                        <li>每次调用都需要同步</li>
                        <li>性能开销较大</li>
                    </ul>
                </div>
            </div>
            
            <h3 class="text-xl font-semibold text-gray-800 mb-4 pl-2 border-l-4 border-purple-500 px-3">2.2 双重检查锁（Double-Checked Locking）</h3>
            <p class="text-gray-700 mb-4">为了减少同步的开销，可以使用双重检查锁定。首先检查实例是否为 <code class="bg-gray-100 px-1 py-0.5 rounded">null</code>，如果是，再进入同步块中进行创建。</p>
            
            <div class="mb-6">
                <div class="code-block">
                    <div class="code-header">
                        <div class="code-dots mr-4">
                            <div class="code-dot"></div>
                            <div class="code-dot"></div>
                            <div class="code-dot"></div>
                        </div>
                        <span class="text-gray-300 text-sm">Singleton.java</span>
                    </div>
                    <div class="code-content">
                        <pre class="text-gray-200"><code>public class Singleton {
    private static volatile Singleton instance;

    private Singleton() {}

    public static Singleton getInstance() {
        if (instance == null) {
            synchronized (Singleton.class) {
                if (instance == null) {
                    instance = new Singleton();
                }
            }
        }
        return instance;
    }
}</code></pre>
                    </div>
                </div>
            </div>
            
            <div class="pros-cons mb-6">
                <div class="bg-green-50 p-4 rounded-lg">
                    <h3 class="font-medium text-green-800 mb-2 flex items-center"><i class="fas fa-thumbs-up mr-2"></i>优点</h3>
                    <ul class="list-disc pl-5 text-green-700 space-y-1">
                        <li>延迟初始化</li>
                        <li>减少同步次数</li>
                        <li>性能优于同步方法</li>
                    </ul>
                </div>
                <div class="bg-red-50 p-4 rounded-lg">
                    <h3 class="font-medium text-red-800 mb-2 flex items-center"><i class="fas fa-thumbs-down mr-2"></i>缺点</h3>
                    <ul class="list-disc pl-5 text-red-700 space-y-1">
                        <li>实现较复杂</li>
                        <li>需要使用volatile关键字</li>
                        <li>JDK5之前仍有问题</li>
                    </ul>
                </div>
            </div>
            
            <div class="bg-yellow-50 p-4 rounded-lg">
                <h3 class="font-medium text-yellow-800 mb-2 flex items-center"><i class="fas fa-exclamation-triangle mr-2"></i>重要提示</h3>
                <p class="text-yellow-700">在JDK5之前，由于Java内存模型的问题，双重检查锁仍可能失效。必须使用<code class="bg-yellow-100 px-1 py-0.5 rounded">volatile</code>关键字修饰实例变量，以防止指令重排序问题。</p>
            </div>
        </div>

        <!-- 3. Static Inner Class -->
        <div class="mb-16">
            <div class="flex items-center mb-6">
                <span class="bg-purple-100 text-purple-800 font-bold rounded-full w-8 h-8 flex items-center justify-center mr-4">3</span>
                <h2 class="text-2xl font-bold text-gray-800">静态内部类（Initialization-on-demand holder idiom）</h2>
            </div>
            <p class="text-gray-700 mb-6">这种方法利用了 Java 类加载机制的线程安全特性，在类加载时不会创建实例，而是当访问静态内部类时才创建。</p>
            
            <div class="mb-8">
                <div class="code-block">
                    <div class="code-header">
                        <div class="code-dots mr-4">
                            <div class="code-dot"></div>
                            <div class="code-dot"></div>
                            <div class="code-dot"></div>
                        </div>
                        <span class="text-gray-300 text-sm">Singleton.java</span>
                    </div>
                    <div class="code-content">
                        <pre class="text-gray-200"><code>public class Singleton {
    private Singleton() {}

    private static class Holder {
        private static final Singleton INSTANCE = new Singleton();
    }

    public static Singleton getInstance() {
        return Holder.INSTANCE;
    }
}</code></pre>
                    </div>
                </div>
            </div>
            
            <div class="pros-cons mb-6">
                <div class="bg-green-50 p-4 rounded-lg">
                    <h3 class="font-medium text-green-800 mb-2 flex items-center"><i class="fas fa-thumbs-up mr-2"></i>优点</h3>
                    <ul class="list-disc pl-5 text-green-700 space-y-1">
                        <li>线程安全</li>
                        <li>延迟初始化</li>
                        <li>无同步开销</li>
                        <li>实现简单优雅</li>
                    </ul>
                </div>
                <div class="bg-red-50 p-4 rounded-lg">
                    <h3 class="font-medium text-red-800 mb-2 flex items-center"><i class="fas fa-thumbs-down mr-2"></i>缺点</h3>
                    <ul class="list-disc pl-5 text-red-700 space-y-1">
                        <li>无法传递参数初始化</li>
                    </ul>
                </div>
            </div>
            
            <div class="bg-blue-50 p-4 rounded-lg">
                <h3 class="font-medium text-blue-800 mb-2 flex items-center"><i class="fas fa-star mr-2 text-blue-500"></i>最佳实践</h3>
                <p class="text-blue-700">静态内部类方式被广泛认为是实现单例模式的最佳方式之一，它结合了线程安全和延迟初始化的优点，同时避免了同步带来的性能开销。</p>
            </div>
        </div>

        <!-- 4. Enum -->
        <div class="mb-16">
            <div class="flex items-center mb-6">
                <span class="bg-purple-100 text-purple-800 font-bold rounded-full w-8 h-8 flex items-center justify-center mr-4">4</span>
                <h2 class="text-2xl font-bold text-gray-800">枚举方式</h2>
            </div>
            <p class="text-gray-700 mb-6">使用枚举类型来实现单例模式，可以充分利用 Java 枚举的特性，它保证了线程安全和防止反序列化攻击。</p>
            
            <div class="mb-8">
                <div class="code-block">
                    <div class="code-header">
                        <div class="code-dots mr-4">
                            <div class="code-dot"></div>
                            <div class="code-dot"></div>
                            <div class="code-dot"></div>
                        </div>
                        <span class="text-gray-300 text-sm">Singleton.java</span>
                    </div>
                    <div class="code-content">
                        <pre class="text-gray-200"><code>public enum Singleton {
    INSTANCE;

    // 可以添加其他方法和属性
    public void doSomething() {
        // 实现业务逻辑
    }
}</code></pre>
                    </div>
                </div>
            </div>
            
            <div class="pros-cons mb-6">
                <div class="bg-green-50 p-4 rounded-lg">
                    <h3 class="font-medium text-green-800 mb-2 flex items-center"><i class="fas fa-thumbs-up mr-2"></i>优点</h3>
                    <ul class="list-disc pl-5 text-green-700 space-y-1">
                        <li>实现极其简单</li>
                        <li>线程安全</li>
                        <li>防止反序列化破坏单例</li>
                        <li>防止反射攻击</li>
                    </ul>
                </div>
                <div class="bg-red-50 p-4 rounded-lg">
                    <h3 class="font-medium text-red-800 mb-2 flex items-center"><i class="fas fa-thumbs-down mr-2"></i>缺点</h3>
                    <ul class="list-disc pl-5 text-red-700 space-y-1">
                        <li>不能延迟初始化</li>
                        <li>不够灵活</li>
                    </ul>
                </div>
            </div>
            
            <div class="bg-purple-50 p-4 rounded-lg">
                <h3 class="font-medium text-purple-800 mb-2 flex items-center"><i class="fas fa-award mr-2 text-purple-500"></i>专家推荐</h3>
                <p class="text-purple-700">这种方法在《Effective Java》中被Joshua Bloch推荐为实现单例的最佳方法。它简洁、安全，并能防御多种攻击方式。</p>
            </div>
        </div>

        <!-- Summary -->
        <div class="bg-white rounded-xl p-6 shadow-md mb-16">
            <h2 class="text-2xl font-bold mb-6 text-gray-800 flex items-center">
                <i class="fas fa-clipboard-list mr-3 text-purple-500"></i>实现方式总结与选择建议
            </h2>
            
            <div class="overflow-x-auto">
                <table class="min-w-full divide-y divide-gray-200">
                    <thead class="bg-gray-50">
                        <tr>
                            <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">实现方式</th>
                            <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">线程安全</th>
                            <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">延迟初始化</th>
                            <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">性能</th>
                            <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">推荐指数</th>
                        </tr>
                    </thead>
                    <tbody class="bg-white divide-y divide-gray-200">
                        <tr class="hover:bg-gray-50">
                            <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">饿汉式</td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">✔️</td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">❌</td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">高</td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm font-medium">
                                <span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-green-100 text-green-800">★★★</span>
                            </td>
                        </tr>
                        <tr class="hover:bg-gray-50">
                            <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">同步方法</td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">✔️</td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">✔️</td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">低</td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm font-medium">
                                <span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-yellow-100 text-yellow-800">★</span>
                            </td>
                        </tr>
                        <tr class="hover:bg-gray-50">
                            <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">双重检查锁</td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">✔️</td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">✔️</td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">中</td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm font-medium">
                                <span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-green-100 text-green-800">★★</span>
                            </td>
                        </tr>
                        <tr class="hover:bg-gray-50">
                            <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">静态内部类</td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">✔️</td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">✔️</td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">高</td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm font-medium">
                                <span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-green-100 text-green-800">★★★★</span>
                            </td>
                        </tr>
                        <tr class="hover:bg-gray-50">
                            <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">枚举方式</td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">✔️</td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">❌</td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">高</td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm font-medium">
                                <span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-green-100 text-green-800">★★★★★</span>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
            
            <div class="mt-6 p-4 bg-gray-100 rounded-lg">
                <h3 class="font-medium text-gray-800 mb-3 flex items-center"><i class="fas fa-check-circle mr-2 text-green-500"></i>最终建议</h3>
                <p class="text-gray-700">
                    <span class="font-medium">优先选择静态内部类或枚举方式</span> - 它们提供了最佳的线程安全性和性能组合。<br>
                    <span class="font-medium">如果需要延迟初始化且不能使用枚举</span> - 选择静态内部类方式。<br>
                    <span class="font-medium">如果可以接受类加载时就创建实例</span> - 简单的饿汉式也是不错的选择。<br>
                    <span class="font-medium">避免使用同步方法</span> - 除非性能不是关键考虑因素。
                </p>
            </div>
        </div>

        <!-- FAQ -->
        <div class="mb-16">
            <h2 class="text-2xl font-bold mb-6 text-gray-800 flex items-center">
                <i class="fas fa-question-circle mr-3 text-purple-500"></i>常见问题解答
            </h2>
            
            <div class="space-y-4">
                <div class="card bg-white p-6 rounded-lg">
                    <h3 class="font-semibold text-lg text-gray-800 mb-2">1. 为什么需要单例模式的线程安全实现？</h3>
                    <p class="text-gray-700">在多线程环境下，如果单例模式的实现不是线程安全的，多个线程可能同时检测到实例为null，从而创建多个实例，破坏了单例模式的约束。这可能导致资源浪费、状态不一致等问题。</p>
                </div>
                
                <div class="card bg-white p-6 rounded-lg">
                    <h3 class="font-semibold text-lg text-gray-800 mb-2">2. volatile关键字在双重检查锁中起什么作用？</h3>
                    <p class="text-gray-700">volatile关键字有两方面作用：<br>
                    1) 保证变量的可见性 - 当一个线程修改了volatile变量，其他线程能立即看到最新值<br>
                    2) 防止指令重排序 - 确保在实例化对象时，对象初始化完成后再将引用赋值给instance变量</p>
                </div>
                
                <div class="card bg-white p-6 rounded-lg">
                    <h3 class="font-semibold text-lg text-gray-800 mb-2">3. 枚举方式是如何防止反射攻击的？</h3>
                    <p class="text-gray-700">Java规范规定不能通过反射创建枚举实例。当尝试使用反射创建枚举实例时，会抛出IllegalArgumentException。这是Java语言层面的保障，使得枚举方式成为最安全的单例实现。</p>
                </div>
            </div>
        </div>
    </div>

    <!-- Footer -->
    <footer class="bg-gray-900 text-white py-8">
        <div class="max-w-5xl mx-auto px-6">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-4 md:mb-0">
                    <h3 class="text-lg font-medium">技术小馆</h3>
                    <p class="text-gray-400 mt-1">探索编程之美</p>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="text-gray-300 hover:text-white transition duration-150 ease-in-out">
                        <i class="fas fa-globe mr-2"></i>http://www.yuque.com/jtostring
                    </a>
                </div>
            </div>
            <div class="mt-8 pt-6 border-t border-gray-800 text-center text-gray-400 text-sm">
                &copy; 2023 技术小馆. 保留所有权利.
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>
```